SET(CMAKE_MODULE_PATH "${ZEVENT_SOURCE_DIR}/cmake/modules")

FIND_PACKAGE(APR REQUIRED)
FIND_PACKAGE(APR-UTIL REQUIRED)
IF(APR_FOUND)
	INCLUDE_DIRECTORIES(${APR_INCLUDE_DIR})
	SET(HAVE_LIBAPR 1)
ENDIF(APR_FOUND)

IF(APR-UTIL_FOUND)
	INCLUDE_DIRECTORIES(${APR-UTIL_INCLUDE_DIR})
	SET(HAVE_LIBAPR-UTIL 1)
ENDIF(APR-UTIL_FOUND)

SET(LIBEVENT_SRC_BUILD 
	iniparser.c
	dictionary.c
	fdqueue.c
	zevent.c
	zevent_mpm.c
	zevent_network.c
	zevent_hooks.c
	scoreboard.c
	pod.c
	log.c
	)
SET(SRC echo.c
	)

ADD_DEFINITIONS(-D_LARGEFILE64_SOURCE -DHAVE_EPOLL -Wall -Wno-strict-aliasing)
SET(CMAKE_C_FLAGS_DEBUG "$ENV{CFLAGS} -O0 -Wall -g  -ggdb")
SET(CMAKE_C_FLAGS_RELEASE "$ENV{CFLAGS} -O3 -Wall")


SET(INC_DIRS ${ZEVENT_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${INC_DIRS})

#SET(LINK_DIRS /home/kacha/dev/apr/lib /home/kacha/dev/apr-util/lib)
#LINK_DIRECTORIES(${LINK_DIRS})

SET(BUILD_SHARED_LIBS on)
SET(ZEVENT_LIB zevent)
ADD_LIBRARY(${ZEVENT_LIB} ${LIBEVENT_SRC_BUILD})
TARGET_LINK_LIBRARIES(${ZEVENT_LIB} ${APR_LIBRARIES} ${APR-UTIL_LIBRARIES})

SET_TARGET_PROPERTIES(zevent PROPERTIES VERSION 1.2 SOVERSION 1)

ADD_EXECUTABLE(echosvc ${SRC})

TARGET_LINK_LIBRARIES(echosvc ${ZEVENT_LIB})

INSTALL(TARGETS echosvc zevent
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION /usr/local/zevent/lib)

